package 力扣日常刷题.木23一月.第11天311;

/**
 * @author 帅小伙
 * @date 2022/3/11
 * @description
 */
public class Demo46股票的最大利润 {


    public int maxProfit(int[] prices) {
        if(prices.length == 0) return 0;
        int ans = 0;
        int min = prices[0];
        for (int i = 1; i < prices.length; i++) {
            if(min > prices[i]) min = prices[i];
            ans = Math.max(ans,prices[i] - min);
        }
        return ans;
    }

}
